home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / extensions / samples / util.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  2KB  |  83 lines

  1. /*
  2.  * Copyright (c) 1994 Silicon Graphics, Inc.
  3.  * 
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee,
  6.  * provided that (i) the above copyright notices and this permission
  7.  * notice appear in all copies of the software and related documentation,
  8.  * and (ii) the name of Silicon Graphics may not be used in any
  9.  * advertising or publicity relating to the software without the specific,
  10.  * prior written permission of Silicon Graphics.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  15.  * 
  16.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL,
  17.  * INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY
  18.  * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  19.  * OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  20.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  21.  * OF THIS SOFTWARE.
  22.  */
  23. /*
  24.  * Misc utility routines.
  25.  */
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <unistd.h>
  30. #include <math.h>
  31. #include <GL/gl.h>
  32. #include "util.h"
  33.  
  34. float x_axis[] = { 1.0, 0.0, 0.0 };
  35. float y_axis[] = { 0.0, 1.0, 0.0 };
  36. float z_axis[] = { 0.0, 0.0, 1.0 };
  37. float nx_axis[] = { -1.0, 0.0, 0.0 };
  38. float ny_axis[] = { 0.0, -1.0, 0.0 };
  39. float nz_axis[] = { 0.0, 0.0, -1.0 };
  40.  
  41. void norm(float v[3])
  42. {
  43.     float r;
  44.  
  45.     r = sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] );
  46.  
  47.     v[0] /= r;
  48.     v[1] /= r;
  49.     v[2] /= r;
  50. }
  51.  
  52. float dot(float a[3], float b[3])
  53. {
  54.     return (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);
  55. }
  56.  
  57. void cross(float v1[3], float v2[3], float result[3])
  58. {
  59.     result[0] = v1[1]*v2[2] - v1[2]*v2[1];
  60.     result[1] = v1[2]*v2[0] - v1[0]*v2[2];
  61.     result[2] = v1[0]*v2[1] - v1[1]*v2[0];
  62. }
  63.  
  64. float length(float v[3])
  65. {
  66.     float r = sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] );
  67.     return r;
  68. }
  69.  
  70. /*
  71.  *  Returns: extension named 'name' is supported.
  72.  */
  73. GLboolean
  74. getExtension(char *name)
  75. {
  76.     const GLubyte *extensions;
  77.  
  78.     extensions = glGetString(GL_EXTENSIONS);
  79.     if (extensions == NULL || *extensions == '\0')
  80.     return GL_FALSE;
  81.     return strstr(extensions, name) != 0;
  82. }
  83.